package com.proposition.user.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.proposition.commons.model.Role;
import com.proposition.commons.model.User;
import com.proposition.user.mapper.UserMapper;
import com.proposition.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户接口实现类
 * @author 杨凯
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements UserService {
	@Autowired
	private UserMapper userDao;

	/**
	 * 获取用户信息
	 */
	@Override
	public User findByName(String userName) {
		return userDao.findByName(userName);
	}

	/**
	 * 获取用户所对应的角色和权限
	 */
	@Override
	public Map<String, Object> listAuthByUserName(String userName) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("allRoles", userDao.findRoleByUserName(userName));
		map.put("allPermissions", userDao.findPermissionByRole(userName));
		return map;
	}

	/**
	 * 获取用户列表
	 */
	@Override
	public List<User> findUserList() {
		return userDao.findUserList();
	}

	/**
	 * 获取角色列表
	 */
	@Override
	public List<Role> findRoleList() {
		return userDao.findRoleList();
	}

	/**
	 * 添加用户
	 */
	@Override
	public boolean addUser(User user) {
		return userDao.addUser(user);
	}

	/**
	 * 判断用户名是否存在
	 */
	@Override
	public boolean checkUserExist(String userName) {
		return userDao.checkUserExist(userName) > 0 ? false : true;
	}



	@Override
	public User findById(String userId) {
		return userDao.findById(userId);
	}

	@Override
	public boolean updateUserInfo(String userId, String realName, String password, String roleId, String telephone) {
		return userDao.updateUserInfo(userId, realName, password, roleId, telephone);
	}

	@Override
	public boolean deleteUserById(String userId) {
		return userDao.deleteUserById(userId);
	}

	@Override
	public boolean changePassword(String userId, String newPassword) {
		return userDao.changePassword(userId,newPassword);
	}


}
